package com.hyts.standard.webflux.meter;

import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;

public class Gauges {

  private static SimpleMeterRegistry registry = new SimpleMeterRegistry();

  public Gauge gauge() {

    AtomicInteger value = registry.gauge("gauge1", new AtomicInteger(0));
    value.set(2);

    List<String> list = registry.gaugeCollectionSize("list.size", Collections.emptyList(), new ArrayList<>());
    list.add("a");

    Map<String, String> map = registry.gaugeMapSize("map.size", Collections.emptyList(), new HashMap<>());
    map.put("a", "b");

    return Gauge.builder("value", this, Gauges::getValue)
        .description("a simple gauge")
        .tag("tag1", "a")
        .register(registry);
  }

  private double getValue() {
    return ThreadLocalRandom.current().nextDouble();
  }


  public static void main(String[] args){
    Gauges gauges = new Gauges();
    gauges.gauge();
    System.out.println(registry.get("gauge1").gauge().value());
    System.out.println(registry.get("list.size").gauge().value());
      //System.out.println(gauges.gauge().);
  }
}
